package keeto.com.vn.bms.network.task;

import java.io.IOException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.SendMsgtoGroupsRequest;
import keeto.com.vn.bms.network.response.SendMsgtoGroupsResponse;
import keeto.com.vn.bms.utils.BMSListener;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskSendMsgtoGroups extends AbstractTask {

	private String title;
	private String Content;
	private	String groupId;
	private String authKey;
	
	public TaskSendMsgtoGroups(BMSListener listener, IBMSCore core,
			String title, String content, String groupId, String authKey) {
		super(listener, core);
		this.title = title;
		Content = content;
		this.groupId = groupId;
		this.authKey = authKey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		SendMsgtoGroupsRequest request = new SendMsgtoGroupsRequest();
		request.setTitle(title);
		request.setGroupId(groupId);
		request.setContent(Content);
		request.setAuthKey(authKey);
		SendMsgtoGroupsResponse response = protocol.SendMsgtoGroups(request);
		for (BMSListener mlistener : listener){
			mlistener.finishSendMsgtoGroups(response.getReturnCode(), response.getResuiltMsg(), response.getIdMsg());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishSendMsgtoGroups(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, null,null);
		}
	}

}
